package com.woniu.controller;

import com.woniu.entity.Result;
import com.woniu.pojo.Label;
import com.woniu.pojo.TeamLabel;
import com.woniu.service.ITeamLabelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 团队——标签中间表 前端控制器
 * </p>
 *
 * @author xiaotang
 * @since 2022-10-12
 */
@RestController
@RequestMapping("/teamLabel")
@Api(tags = "团队标签中间表管理")
public class TeamLabelController extends BaseController{

    @Autowired
    private ITeamLabelService teamLabelService;

    @ApiOperation("增加")
    @PostMapping
    public Result add(@RequestBody TeamLabel teamLabel){
        boolean flag = teamLabelService.save(teamLabel);

        return toResult(flag);
    }

    @ApiOperation("修改")
    @PutMapping
    public Result modify(@RequestBody TeamLabel teamLabel){
        boolean flag = teamLabelService.updateById(teamLabel);
        return toResult(flag);
    }

    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    public Result remove(@PathVariable Long id){
        boolean flag = teamLabelService.removeById(id);
        return toResult(flag);
    }

    @ApiOperation("根据团队id查询标签")
    @GetMapping("/{id}")
    public Result queryById(@PathVariable Long id){
        List<Label> labelList = teamLabelService.getByTeamId(id);
        return toDataResult(labelList);
    }

    @ApiOperation("对团队中间表进行编辑操作")
    @PostMapping("/{teamId}")
    public Result addVideos(@PathVariable Long teamId,
                            @RequestBody List<Long> selectedLabelIds){
        teamLabelService.addLabels(teamId, selectedLabelIds);
        return success();
    }

}
